package com.zzyl.controller;


import com.github.pagehelper.Page;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yaml.snakeyaml.events.Event;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

/**
 * @Description NursingController
 * @Author pengtao
 * @Date 2025-05-08  10:36
 */
@RequestMapping("/nursing_project")
@RestController
@Api(tags = "护理项目")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;


    //分页查询
    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "名称")
            @RequestParam(value = "name" ,required = false )String name,
            @ApiParam(value = "状态：0-禁用 , 1-启用 ")
            @RequestParam(value = "status" ,required = false)Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ){
        PageResponse<NursingProjectVo> byPage = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(byPage);
    }


    //新增
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(@RequestBody NursingProjectVo nursingProjectVo){
       nursingProjectService.add(nursingProjectVo);
       return success();
   }




   //删除
    @DeleteMapping("/{id}")
     @ApiOperation("删除护理项目")
    public ResponseResult delete(@PathVariable("id") Long id){
        nursingProjectService.delete(id);
        return success();
    }
    //改
    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectVo nursingProjectVo){
        nursingProjectService.update(nursingProjectVo);
        return success();
    }

    //id查
    @GetMapping("/{id}")
    @ApiOperation("查询护理项目")
    public ResponseResult read(@PathVariable("id") Long id){
        NursingProjectVo read = nursingProjectService.read(id);
        return ResponseResult.success(read);
    }
    //查所有
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult getAll(){
        List<NursingProjectVo> all = nursingProjectService.getAll();
        return ResponseResult.success(all);
    }

    //启用禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用护理项目")
    public ResponseResult enableOrDisable(
            @ApiParam(value = "护理项目ID", required = true)
            @PathVariable Long id,
            @ApiParam(value = "护理项目状态", required = true)
            @PathVariable Integer status) {
        nursingProjectService.updateStatus(id,  status);
        return success("启用/禁用护理项目成功");
    }


}
